/***********************************************************
* 
*     File Name:  taskSink.cpp
* 
*        Author:  Algolc
* 
*          mail:  17360224@qq.com
* 
*  Created Time:  Wed 11 Jul 2018 03:57:01 PM CST
* 
***********************************************************/

#include "zhelpers.h"
#include <unistd.h>
int main() {
    void* context = zmq_ctx_new();
    void *receiver = zmq_socket(context, ZMQ_PULL);
    zmq_bind(receiver, "tcp://*:5558");
    //用于worker控制的套接字
    void* controller = zmq_socket(context, ZMQ_PUB);
    zmq_bind(controller, "tcp://*:5559");

    //等待批处理开始
    char* tmp_str = s_recv(receiver);
    free(tmp_str);

    //启动时钟
    int64_t start_time = s_clock();

    //处理100个确认
    for (int count = 0; count < 100; ++count) {
        char* tmp_string = s_recv(receiver);
        free(tmp_string);
        if ((count/10)*10 == count) {
            printf(":");
        } else {
            printf(".");
        }
        fflush(stdout);
    }
    printf("Total elapsed time:%d msec\n", (int)(s_clock() - start_time));

    //发送kill信号给工人
    s_send(controller, "KILL");

    sleep(1);
    zmq_close(receiver);
    zmq_close(controller);
    zmq_ctx_destroy(context);
    return 0;
}
